Welcome to Sophie Nickerson's C# Programming Primer!
This is a website where you will learn the basics about programming in C#
Console Output Windows Output Declare and Initialize Variables
Brief Overview of C#
C# is an easy to learn, modern language created by Microsoft. It is a general purpose programming language, and is both object and component oriented. C# is a structured language and produces efficient programs.
How to Create a Program
Console Program:
- Select Console Application
- Console.WriteLine(“text”);
- Console.ReadLine();
- Press start to run program
Windows Form Program:
- Select Windows Forms Application
- Drag a button onto form
- Double-click the button and add code:
- MessageBox.Show(“text”);
How to Create an Output
Console Output:
- Select Console Application
- Console.WriteLine(“text”);
- Console.ReadLine();
- Press start to run program
Top of Page
Top of Page
Windows Output
example with label and richtextbox
- Select Windows Form Application
- Drag a button and name it btnAnything
- Change the Text to anything you want
- Bring out a label and name it lblAnything
- Bring out a richtextbox and name it rtbAnything
- Double click the button
- Enter code:
- lblAnything.Text = “text”;
- rtbAnything.Text = “text”;
- Press start to run program
Top of Page
Top of Page
How to Declare and Initialize Variables
Boolean Variables
- Boolean variables only store two values: True or False
- To declare a Boolean Variable
- To Initialize a Boolean Variable
Integer Variables
- Integers are useful for counting and keeping track of numbers without decimals
- To declare an Integer Variable
- To initialize an Integer Variable
Floating Point (Double, or decimal)
- If dealing with fractions or decimals use a floating point. The most common data type to use is a Double.
- To declare a Double Variable
- To initialize a Double Variable
String Variables
- If not using variable to do math, or you want to represent words use String variables. Strings can be any combination of letters, numbers, or punctuation marks.
- To declare a String Variable
- To initialize a String Variable
Note: Declaring and Initializing Variables
You can also declare and initialize a variable in one statement of code
Top of Page